<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>南丁格尔玫瑰图</title>
  <!-- 引入 ECharts.js -->
  <script src="https://cdn.jsdelivr.net/npm/echarts@5.2.2/dist/echarts.min.js"></script>
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  <style>
    html, body {
      height: 100%;
      margin: 0;
      padding: 0;
    }
    #chart {
      width: 100%;
      height: 100%;
      min-height: 280px; /* 设置最小高度，防止内容过小时显示异常 */
    }
  </style>
</head>
<body>
<div id="chart" style="width: 600px; height: 400px;"></div>

<script>
  $(document).ready(function() {
    // 发送Ajax请求获取温度数据
    $.ajax({
      url: "/temperature-data4",
      type: "GET",
      success: function(data) {
        // 解析返回的数据
        var weekStartDates = data.weekStartDates;
        var averageTemperatures = data.averageTemperatures;

        // 初始化ECharts实例
        var myChart = echarts.init(document.getElementById("chart"));

        // 配置南丁格尔玫瑰图的数据
        var option = {
          title: {
            text: "南丁格尔玫瑰图"
          },
          tooltip: {
            trigger: "item"
          },
          legend: {
            data: weekStartDates
          },
          series: [
            {
              name: "温度",
              type: "pie",
              radius: "55%",
              center: ["50%", "50%"],
              roseType: "radius",
              data: (function() {
                var seriesData = [];
                for (var i = 0; i < weekStartDates.length; i++) {
                  seriesData.push({
                    name: weekStartDates[i],
                    value: averageTemperatures[i]
                  });
                }
                return seriesData;
              })()
            }
          ]
        };

        // 使用刚指定的配置项和数据显示图表
        myChart.setOption(option);
      },
      error: function(xhr, status, error) {
        console.log("Error: " + error);
      }
    });
  });
</script>
</body>
</html>